var verify_item_have_agreement = JSON.parse('{"CODE":0, "ACTION":"","LEVEL":"T1", "MSG":"","DATA":"","SCRIPTNAME":"verify_item_have_agreement"}');
var haveAgreementIdList = []
var haveAgreementIdSet = []
if (active_discount == 1) {
    var discountStartDateHaveAgreement = ""
    var discountEndDateHaveAgreement = ""
    if (discount_range === 'price') {
        discountStartDateHaveAgreement = retail_start_date;
        discountEndDateHaveAgreement = retail_end_date;
    } else if (discount_range === 'cost') {
        discountStartDateHaveAgreement = cost_start_date;
        discountEndDateHaveAgreement = cost_end_date;
    }
    if (isNull(discountEndDateHaveAgreement)) {
        discountEndDateHaveAgreement = "2049-12-31"
    }

    discountStartDateHaveAgreement = getNewBeginDate(new Date(discountStartDateHaveAgreement));
    discountEndDateHaveAgreement = getNewEndDate(new Date(discountEndDateHaveAgreement));

    var verify_item_have_agreement_url = "https://mdc-dev-aloha-gateway.cn.wal-mart.com/spp-price-change/server/item-relation/check-agreement-item";

    var verify_item_have_agreement_param = [{
        "areaCode": trait_nbr,
        "effectiveDate": discountStartDateHaveAgreement,
        "expirationDate": discountEndDateHaveAgreement,
        "itemNbr": item_nbr,
        "storeId": store_id
    }]

    var verify_item_have_agreement_params = {
        "param": verify_item_have_agreement_param
    };

    var verify_item_have_agreement_result = JSON.parse(func_post(verify_item_have_agreement_url, JSON.stringify(verify_item_have_agreement_params)));

    var item_have_agreement_result_list = verify_item_have_agreement_result.result;
    if (!isNull(item_have_agreement_result_list)) {
        item_have_agreement_result_list.forEach(function (item_have_agreement) {
            haveAgreementIdList.push(item_have_agreement.id)
        })
    }

}

if (haveAgreementIdList.length > 0) {
    haveAgreementIdList.forEach(function (haveAgreementId) {
        if (haveAgreementIdSet.indexOf(haveAgreementId) == -1) {
            haveAgreementIdSet.push(haveAgreementId);
        }
    })
    verify_item_have_agreement.CODE = 2;
    verify_item_have_agreement.ACTION = 'error';
    verify_item_have_agreement.MSG = '该商品存在已生效的VA协议，协议编号[' + haveAgreementIdSet.join(',') + ']，如需截停，请到AMS系统进行处理';
}

JSON.stringify(verify_item_have_agreement);